<template>
  <div class="clearfix selector">
    <div class="type-wrap logo">
      <div class="fl key brand">品牌</div>
      <div class="value logos">
        <!-- 品牌logo列表 ---->
        <ul class="logo-list">
          <li v-for="trademark in trademarkList" :key="trademark.tmId" @click="handleTrademark(trademark)">{{
            trademark.tmName }}</li>
        </ul>
      </div>
      <!-- <div class="ext">
        <a href="javascript:void(0);" class="sui-btn">多选</a>
        <a href="javascript:void(0);">更多</a>
      </div> -->
    </div>

    <!-- 属性列表，生成对应的搜索条件 -->
    <div class="type-wrap" v-for="attr in attrsList" :key="attr.attrId">
      <!-- 属性名称 ---->
      <div class="fl key">{{ attr.attrName }}</div>
      <div class="fl value">
        <ul class="type-list">
          <!-- 属性值列表 ---->
          <li v-for="attrValue in attr.attrValueList" :key="attrValue" @click="handleAttrInfo(attr, attrValue)">
            <a>{{ attrValue }}</a>
          </li>

        </ul>
      </div>
      <div class="fl ext"></div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'SearchSelector',
  // props:['attrsList','trademarkList','sendTrademark'],
  computed: {
    ...mapGetters(["trademarkList", "attrsList"]) // 映射vuex中的state数据
  },
  methods: {
    handleTrademark(trademark) {
      // 点击品牌logo，需要参数向服务器发送请求获取相应的数据,在父组件中发请求，并将数据传递给子组件
      //自定义事件，向父组件传递参数
      this.$emit("trademarkInfo", trademark);
    },
    // 点击属性值，需要参数向服务器发送请求获取相应的数据,在父组件中发请求，并将数据传递给子组件
    handleAttrInfo(attr, attrValue) {
      this.$emit("attrInfo", attr, attrValue);
    }
  },
}

</script>

<style lang="less" scoped>
.selector {
  border: 1px solid #ddd;
  margin-bottom: 5px;
  overflow: hidden;

  &:hover {
    cursor: pointer;
  }

  .logo {
    border-top: 0;
    margin: 0;
    position: relative;
    overflow: hidden;

    .key {
      padding-bottom: 87px !important;
    }
  }

  .type-wrap {
    margin: 0;
    position: relative;
    border-top: 1px solid #ddd;
    overflow: hidden;

    .key {
      width: 100px;
      background: #f1f1f1;
      line-height: 26px;
      text-align: right;
      padding: 10px 10px 0 15px;
      float: left;
      font-size: 16px;

      &:hover {
        background: #89dff7;
      }
    }

    .value {
      overflow: hidden;
      padding: 10px 0 0 15px;
      color: #333;
      margin-left: 120px;
      padding-right: 90px;

      .logo-list {
        li {
          display: inline-block;
          border: 1px solid #d1d1d1;
          border-radius: 5px;
          margin: 5px;
          width: 100px;
          height: 52px;
          text-align: center;
          line-height: 52px;
          overflow: hidden;
          text-overflow: ellipsis; /* 超出部分显示省略号 */
          white-space: nowrap; 
          font-weight: 700;
          color: #e1251b;
          background-color: #f0f0f0;
          font-style: italic;  /* 斜体 */
          font-size: 16px;

          &:hover {
            background: #89dff7;
          }

          img {
            max-width: 100%;
            vertical-align: middle;
          }
        }
      }

      .type-list {
        li {
          float: left;
          display: block;
          margin-right: 30px;
          line-height: 26px;

          a {
            text-decoration: none;
            color: #666;
            font-size: 16px;
            font-weight: 400;
            padding: 0 5px;

            &:hover {
              color: #e1251b;
            }
          }
        }
      }
    }

    .ext {
      position: absolute;
      top: 10px;
      right: 10px;

      .sui-btn {
        display: inline-block;
        padding: 2px 14px;
        box-sizing: border-box;
        margin-bottom: 0;
        font-size: 12px;
        line-height: 18px;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        padding: 0 10px;
        background: #fff;
        border: 1px solid #d5d5d5;
      }

      a {
        color: #666;
      }
    }
  }
}
</style>